package ai;

import logic.common.player.Player;
import logic.nodes.TeamNode;
import map.spawnStation.SpawnStation;

/**
 * This {@link AbstractPilotController} flies the {@link Hunter} to a {@link SpawnStation}. If the pilot is 
 * within the Action-Radius of the {@link SpawnStation}, it will stop there until it gets new orders.
 * 
 * @author Wasserleiche
 */
public class CaptureController extends AbstractPilotController {
	
	private static final long serialVersionUID = 1L;
	
	public CaptureController(Player bot) {
		super(bot);
	}
	
	@Override
	public void delayedUpdate(float time) {
		if(!checkAIEnabled()) return;
		
		super.delayedUpdate(time);
		
		TeamNode target = bot.getBotTarget();
		
		if(target == null || !(target instanceof SpawnStation)) return;
		SpawnStation station = (SpawnStation)target;
				
		float dist = station.getLocalTranslation().distance(bot.getHunter().getLocalTranslation());
		if(dist <= station.getActionRadius()) {
			boost(false);
			bot.getHunter().getMoveForwardController().stop(true);
		} else {
			bot.getHunter().getMoveForwardController().stop(false);
			rotateTo(station.getLocalTranslation(), agility * time, false);
			boost(true);
		}
	}
	
	/**
	 * Returns zero because there should be no time-limit for capturing.
	 * @return zero.
	 */
	@Override
	public float getTargetTime() { return 0f; }
}